package cn.wolfcode.business.controller;


import cn.wolfcode.business.domain.BusAppointment;
import cn.wolfcode.business.service.BusAppointmentService;
import cn.wolfcode.common.core.controller.BaseController;
import cn.wolfcode.common.core.domain.AjaxResult;
import cn.wolfcode.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/business/appointment")
public class BusAppointmentController extends BaseController {

    @Autowired
    BusAppointmentService busAppointmentService;

    /**
     * 查询养修预约信息表 ----注意分页的返回值类型是 TableDataInfo
     * @param busAppointment 传一个参数用于高级查询充作过滤条件
     * @return 返回符合条件的所有预约信息
     */
    @GetMapping("/list")
    public TableDataInfo list(BusAppointment busAppointment){
        //1.调用一个父类封装的分页方法
        startPage();
        List<BusAppointment> list=busAppointmentService.selectBusAppointmentList(busAppointment);
        return getDataTable(list);
    }

    /**
     * 根据id查询一条预约信息，用于编辑时回显页面
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id){
        return AjaxResult.success(busAppointmentService.getInfo(id));
    }

    /**
     * 新增一条养修预约信息
     * @param busAppointment
     * @return
     */
    @PostMapping
    public AjaxResult add(@RequestBody BusAppointment busAppointment){
        return AjaxResult.success(busAppointmentService.add(busAppointment));
    }

    /**
     * 修改预约信息
     * @param busAppointment
     * @return
     */
    @PutMapping
    public AjaxResult update(@RequestBody BusAppointment busAppointment){
        return AjaxResult.success(busAppointmentService.update(busAppointment));
    }

    /**
     * 到店功能
     */
    @PatchMapping(value ="/{id}",headers = "cmd=arrival")
    public AjaxResult arrival(@PathVariable Long id){
        return AjaxResult.success(busAppointmentService.arrival(id));
    }
    /**
     * 取消功能
     */
    @PatchMapping(value ="/{id}",headers = "cmd=cancel")
    public AjaxResult cancel(@PathVariable Long id){
        return AjaxResult.success(busAppointmentService.cancel(id));
    }

    /**
     * 删除功能
     */
    @DeleteMapping("/{id}")
    public AjaxResult deleteById(@PathVariable Long id){
        return AjaxResult.success(busAppointmentService.deleteById(id));
    }

}
